package com.cn.demo.controller;

import com.cn.demo.entity.*;
import com.cn.demo.service.*;
import com.cn.demo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/student/operation")
public class StudentOperationController {

    @Autowired
    private CurriculumService curriculumService;

    @Autowired
    private StudentService studentService;

    @Autowired
    private DesignService designService;

    @Autowired
    private ExperimentService experimentService;

    @Autowired
    private InternshipService internshipService;

    @Autowired
    private InternshipLogService internshipLogService;

    @Autowired
    private TeachingService teachingService;

    @Autowired
    private WaitJoinCurriculumService waitJoinCurriculumService;

    @GetMapping(value = "/getCurriculum")
    public Result get(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "limit", defaultValue = "5") Integer limit,
                      @RequestParam(value = "studentId", required = true) String studentId,
                      @RequestParam(value = "teacherId", required = false) String teacherId,
                      @RequestParam(value = "curriculumId", required = false) String curriculumId,
                      @RequestParam(value = "curriculumName", required = false) String curriculumName
    ) {
        Curriculum curriculum = new Curriculum();
        curriculum.setTeacherId(teacherId);
        curriculum.setCurriculumId(curriculumId);
        curriculum.setCurriculumName(curriculumName);
        return curriculumService.getByStudentId(page, limit, curriculum,studentId);
    }


    /**
     * 查询是否有课程设计的题目
     * 展示队员列表
     */
    @GetMapping(value = "/getDesignSubject")
    public Result getDesignSubject(@RequestParam(value = "studentId", required = true) String studentId,
                                     @RequestParam(value = "curriculumDesignId", required = true) String curriculumDesignId){
        return designService.getDesignSubject(studentId, curriculumDesignId);
    }
    /**
     *
     * 展示我加入该班的已经有创建的项目
     */
    @GetMapping(value = "/getDesignSubjectAll")
    public Result getDesignSubjectAll(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "limit", defaultValue = "5") Integer limit,
                                   @RequestParam(value = "studentId", required = true) String studentId,
                                   @RequestParam(value = "curriculumDesignId", required = true) String curriculumDesignId){
        return designService.getDesignSubjectAll(studentId, curriculumDesignId,page,limit);
    }

    /**
     * 创建课程设计题目
     */

    @PostMapping(value = "/establishDesign")
    public Result establishDesign(@RequestBody Map<String,Object> map){
        String studentId = (String)map.get("studentId");
        String subject = (String)map.get("subject");
        String curriculumDesignId = (String)map.get("curriculumDesignId");
        return  designService.establishDesign(studentId,subject,curriculumDesignId);
    }

    /**
     * 加入已有的课程设计
     */

    @PostMapping(value = "/designJoinTeam")
    public Result designJoinTeam(@RequestBody Map<String,Object> map){
        //课程设计项目ID
        //学生ID
        String studentId = (String)map.get("studentId");
        String designId = (String)map.get("designId");
        return  designService.designJoinTeam(studentId,designId);
    }


    /**
     * 查询是否有实验题目
     * 展示
     */
    @GetMapping(value = "/getExperimentSubject")
    public Result getExperimentSubject(@RequestParam(value = "studentId", required = true) String studentId,
                                   @RequestParam(value = "curriculumExperimentId", required = true) String curriculumExperimentId){
        return experimentService.getExperimentSubject(studentId, curriculumExperimentId);
    }

    /**
     * 创建实验题目
     */
    @PostMapping(value = "/addExperimentSubject")
    public Result addExperimentSubject(@RequestBody Experiment experiment){
        return experimentService.addExperimentSubject(experiment);
    }

    /**
     * 查询是否有实习
     */
    @GetMapping(value = "/getInternshipCorporation")
    public Result getInternshipCorporation(@RequestParam(value = "studentId", required = true) String studentId,
                                       @RequestParam(value = "curriculumInternshipId", required = true) String curriculumInternshipId){
        return internshipService.getInternshipCorporation(studentId, curriculumInternshipId);
    }

    /**
     * 创建实习公司
     */
    @PostMapping(value = "/addInternshipCorporation")
    public Result addInternshipCorporation(@RequestBody Internship internship){
        return internshipService.addInternshipCorporation(internship);
    }


    /**
     * 实习日志打卡
     */
    @PostMapping(value = "/addInternshipLog")
    public Result addInternshipLog(@RequestBody InternshipLog internshipLog){

        return internshipLogService.addInternshipLog(internshipLog);
    }



    /**
     * 展示实习日志
     */
    @GetMapping(value = "/getInternshipLogAll")
    public Result getInternshipLogAll(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "limit", defaultValue = "5") Integer limit,
                                      @RequestParam(value = "studentId", required = true) String studentId,
                                      @RequestParam(value = "curriculumInternshipId", required = true) String curriculumInternshipId){
        return internshipLogService.getInternshipLogAll(studentId, curriculumInternshipId,page,limit);
    }

    /**
     * 加入课程班级
     */
    @PostMapping(value = "/joinCurriculumOrganization")
    public Result joinCurriculumOrganization(@RequestBody Map<String,Object> map){
        String studentId = (String)map.get("studentId");
        String organizationId = (String)map.get("organizationId");
        return teachingService.joinCurriculum(studentId,organizationId);
    }

    @PostMapping(value = "/modifyPassword")
    public Result modifyPassword(@RequestBody Map<String,Object> map) {
        String oldPassword = (String) map.get("oldPassword");
        String affirmPassword = (String) map.get("affirmPassword");
        String studentId = (String) map.get("studentId");
        return studentService.modifyPassword(studentId,oldPassword,affirmPassword);
    }

    @GetMapping(value = "/info")
    public Result info(@RequestParam("studentId") String studentId){
        return studentService.getByStudentId(studentId);
    }


    /**
     * 查询你某位老师下面的课程
     * @param page
     * @param limit
     * @param teacherId
     * @return
     */
    @GetMapping(value = "getCurriculumByTeacherId")
    public Result getCurriculumByTeacherId(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "limit", defaultValue = "5") Integer limit,
                                           @RequestParam(value = "teacherId", required = true) String teacherId){
        return curriculumService.getCurriculumByTeacherId(page,limit,teacherId);
    }

    /**
     * 加入课程
     */

    @PostMapping(value = "/joinCurriculum")
    public Result joinCurriculum(@RequestBody Map<String,Object> map){
        String studentId = (String)map.get("studentId");
        String curriculumId = (String)map.get("curriculumId");
        return waitJoinCurriculumService.joinCurriculum(studentId,curriculumId);
    }




}
